// import {findNameInOptions} from '@/utils'

//全局filters 汇总

// 使用示例<div>{{sex | getSex}}</div>

export function getSex (sexStatus)  {
  // console.log(sexStatus)
  let  sexName = ''
  if (sexStatus != null) {
    switch (sexStatus) {
      case '0': sexName = "男"
        break;
      case '1': sexName = "女"
        break;
      default: sexName = "未知"
    }
  } else {
    sexName = "未知"
  }
  return sexName;
}

/**
 * <div>{{"13485755520" | hiddenPhone}}</div>
 * 手机号隐藏。如13277924031 => 132****4031
 * @param {*} tel 手机号
 * @param {*} start 隐藏的开始位，包含该位，默认4
 * @param {*} end 隐藏截至位，包含该位， 默认7
 */
export const hiddenPhone = (tel, start = 4, end = 7) => {
  if (!tel) return '手机号不存在'
  else {
    start--
    let firstPart = tel.slice(0, start)
    let hiddenPart = ''.padStart((end - start), '*')
    let lastPart = tel.slice(end, tel.length)
    return `${ firstPart }${ hiddenPart }${ lastPart }`
  }
}

export const $pointToYuan = (val) => {
  if (!+val) return `0`
  else return `￥ ${ val / 100 }`
}

export const $pointToYuanUnit = (val, unit = '元') => {
  if (!+val) return `0${ unit }`
  else return `${ val / 100 }${ unit }`
}

export const $amountUnit = (value, unit = '元') => {
  if (!+value) return `0${ unit }`
  else return `${ value }${ unit }`
}

// 分转元
export const $number2Price = (number) => {
  number = +number
  if (!number) return '0'
  return (number / 100).toFixed(2)
}
/*export const $findNameInOptions = (value, options = []) => {
  return findNameInOptions(options, value)
}*/


/**
 * 10000 => "10,000"
 * @param {number} num
 */
export function toThousandFilter(num) {
  return (+num || 0).toString().replace(/^-?\d+/g, m => m.replace(/(?=(?!\b)(\d{3})+$)/g, ','))
}

/**
 * Upper case first char
 * @param {String} string
 */
export function uppercaseFirst(string) {
  return string.charAt(0).toUpperCase() + string.slice(1)
}

/*时间戳转换filter*/
export function times(timestamp) {
  let time = new Date(timestamp)
  let year = time.getFullYear()
  let month = time.getMonth() + 1
  let date = time.getDate()
  let hours = time.getHours()
  let minute = time.getMinutes()
  let second = time.getSeconds()

  if (month < 10) { month = '0' + month }
  if (date < 10) { date = '0' + date }
  if (hours < 10) { hours = '0' + hours }
  if (minute < 10) { minute = '0' + minute }
  if (second < 10) { second = '0' + second }
  return year + '-' + month + '-' + date + ' ' + hours + ':' + minute + ':' + second
}
